package com.gupt.youhd.controller;
/*
@author name
@data 2023/4/24-10:25
*/

import com.gupt.youhd.common.R;
import com.gupt.youhd.entity.Image;
import com.gupt.youhd.mapper.ImageMapper;
import com.gupt.youhd.entity.Shop;
import com.gupt.youhd.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private ImageMapper imageMapper;

    //查询商品信息
    @GetMapping
    public R<List<Shop>> product(HttpServletRequest request){

        List<Shop> shops = productService.retrieveProductBySchoolName(request);

        return R.success(shops);
    }


    //模糊查询商品信息
    @GetMapping("vague")
    public R<Object> getProduct(HttpServletRequest request,String keyword){

        List<Shop> shops = productService.mohuRetrieveShopProductBySchoolIdAndBrief(request,keyword);
        if(shops.size() > 0){
            return R.success(shops);
        }
        return R.error("换关键词试试 8");
    }

    /**
     * 获取轮播图 图片
     * @return
     */
    @GetMapping("getImg")
    public R<List<Image>> getImg(){
        List<Image> images = imageMapper.retrieveImageByProId(0);
        return R.success(images);
    }
}
